<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>基本信息</title>
    <link rel="stylesheet" type="text/css" href="../../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../../css/html/issued/post_your_want_frm.css" />
    <style>
        .list_box {
            padding: 0 0.75rem;
        }

        .list_item {
            display: flex;
            justify-content: space-between;
            border-bottom: 1px solid #eee;
            line-height: 2.5rem;
        }

        .aui-icon-right {
            color: #ccc;
        }

        .apply_update {
            display: flex;
            align-items: center;
        }

        .apply_update_btn {
            width: 3.8rem;
            font-size: 0.6rem;
            background: #0689FB;
            color: #fff;
            border-radius: 0.2rem;
            text-align: center;
            line-height: 1rem;
            margin-left: 0.3rem;
        }
        [v-clock]{display: none;}
    </style>
</head>

<body>
    <div id="app" v-clock>
        <div class="aui-content aui-margin-b-15">
            <ul class="aui-list aui-form-list" style="border-bottom:0.5rem solid #f6f6f6;">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">姓名</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.user_name" placeholder="请输入姓名">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">昵称</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.nickname" placeholder="请输入昵称">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">性别</div>
                        <div class="aui-list-item-input">
                            <div class="aui-list-item-input" style="display:flex;justify-content: flex-end;padding-right:0;">
                                <label><input class="aui-radio" type="radio" value="2" v-model="info.user_sex" name="demo1"> 女</label>
                                <label><input class="aui-radio" type="radio" value="1" v-model="info.user_sex" name="demo1"> 男</label>
                            </div>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">年龄</div>
                        <div class="aui-list-item-input">
                            <input type="number" v-model="info.user_age" placeholder="请填写和身份证匹配的年龄">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">所在地</div>
                        <div class="aui-list-item-input" @click="openCity()">
                            <input type="text" disabled v-model="info.region" placeholder="请选择">
                        </div>
                    </div>
                </li>
            </ul>

            <div class="aui-content-padded">
                <div style="line-height:2rem;">个人介绍</div>
                <textarea name="" id="" class="textarea" placeholder="请输入个人职能介绍，20字以内" v-model='info.user_introduction'></textarea>
                <div class="btn" @click="submit()">保存</div>
            </div>

        </div>
    </div>
</body>
<script src="../../../../script/api.js" charset="utf-8"></script>
<script src="../../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},
            info: {
                user_id: '',
                nickname: '',
                user_name: '',
                user_sex: 1,
                user_age: '',
                region_provinceid: '',
                region_cityid: '',
                region_areaid: '',
                region: '',
                user_introduction: '',
                user_status: ''
            }
        },
        methods: {
            init() {
                this.userInfo = get_local('userInfo');
                // 获取用户信息
                this.getUserInfo();
            },
            getUserInfo() {
                var that = this;
                _ajax(Config.api.UserGetUserBase, {
                    user_id: this.userInfo.user_id
                }, function(ret) {
                    if (ret.code === 200) {
                        that.info = ret.data;
                        that.info.user_id = that.userInfo.user_id;
                        that.info.user_status = that.userInfo.user_status;
                    }
                });

            },
            submit() {
                var that = this;
                if (!is_define(this.info.user_name)) {
                    $toast("请输入姓名");
                    return;
                } else if (!is_define(this.info.nickname)) {
                    $toast("请输入昵称");
                    return;
                } else if (!is_define(this.info.region)) {
                    $toast("请选择所在地");
                    return;
                } else if (!is_define(this.info.user_introduction)) {
                    $toast("请输入个人职能介绍");
                    return;
                } else if (!is_define(this.info.user_age)) {
                    this.info.user_age = 0;
                }
                console.log(JSON.stringify(this.info));
                _ajax(Config.api.UserUpdateUserBase, this.info, function(ret) {
                    if (ret.code === 200) {
                        $toast("保存成功");
                        that.userInfo.user_status = ret.data.user_status;
                        set_local('userInfo', that.userInfo);

                        api.execScript({
                            name: 'main',
                            frameName: 'my',
                            script: 'vm.gerUserInfo();'
                        });

                        setTimeout(function() {
                            close_w();
                        }, 1000);
                    }
                });
            },
            openWin(name) {
                var winInfo = {
                    apply_update: {
                        name: 'apply_update_win',
                        url: './apply_update_win.html'
                    },
                };
                if (name) {
                    open_w(winInfo[name].name, winInfo[name].url);
                } else {
                    $toast("正在开发中...");
                }
            },
            openCity() {
                var url = '../../../city/city_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: api.winHeight - api.frameHeight,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                    }
                });
            },
        }
    });

    function setCity(province, city, area) {

        vm.info.region_provinceid = province.code;
        vm.info.region_cityid = city.code;
        vm.info.region_areaid = area.code;

        vm.info.region = province.name + '-' + city.name + '-' + area.name;
    }
</script>

</html>
